var contributeCompanyList = new Ext.data.JsonStore({
			url : 'contributeCompany_active_list.action',
			root : 'contributeCompanys',
			fields : ['contributeCompanyId', 'contributeCompanyName']
		});

contributeCompanyList.load();



var ds = new Ext.data.Store({
			proxy : new Ext.data.HttpProxy({
						url : 'statistics_statisticsCompany_list.action',
						method : 'POST'
					}),
			reader : new Ext.data.JsonReader({
						root : 'companyList'
					}, [{
								name : 'statType',
								mapping : 'statType',
								convert : function(value, record) {
									if (value == 161) {
										return '稿件数量';
									} else if (value == 162) {
										return '文字数量';
									}
								}
							}, {
								name : 'num',
								mapping : 'num',
								type : 'long'
							}])
		});

var cm = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), {
			header : '统计类型',
			width : 200,
			dataIndex : 'statType',
			sortable : true
		}, {
			header : "数目",
			width : 200,
			dataIndex : 'num',
			sortable : true
		}]);


var text=['稿件数量','文字字数'];
var tbarName=[];
var statType=0;
var statisticsCls=['statistics_manuscript','statistics_text'];

for(var i=0;i<text.length;i++){
	tbarName[i]= new Ext.Button({
		text: text[i],
		iconCls: statisticsCls[i],
		width: 100,
		handler: function(value){
		if(value.text=='稿件数量'){
			statType=1;
		}else if(value.text=='文字字数'){
			statType=2;	
		}
		var currentYear = new Date().getFullYear();
		
		var comboYearData = [['1', eval(currentYear)], ['2', eval(currentYear) - 1], ['3', eval(currentYear) - 2], ['4', eval(currentYear) - 3], ['5', eval(currentYear) - 4], ['6', eval(currentYear) - 5], ['7', eval(currentYear) - 6], ['8', eval(currentYear) - 7], ['9', eval(currentYear) - 8], ['10', eval(currentYear) - 9], ['11', eval(currentYear) - 10]];
		
		var comboQuarterData = [['4', '4'], ['3', '3'], ['2', '2'], ['1', '1']];
		
		var comboMonthData = [['12', '12'], ['11', '11'], ['10', '10'], ['9', '9'], ['8', '8'], ['7', '7'], ['6', '6'], ['5', '5'], ['4', '4'], ['3', '3'], ['2', '2'], ['1', '1']];
		
		var dstore=new Ext.data.SimpleStore({
			data: comboYearData,
			fields: ['value', 'text']
		});
		var yearOne = new Ext.form.ComboBox({
			store:dstore,
			name: 'year',
			fieldLabel: '年',
			emptyText: '请选择',
			mode: 'local',
			triggerAction: 'all',
			valueField: 'value',
			displayField: 'text',
			itemCls: 'form_text',
			id: 'yearOne',
			editable: false,
			columnWidth: .33
		});
		
		var quarterOne = new Ext.form.ComboBox({
			store: new Ext.data.SimpleStore({
				fields: ['value', 'text'],
				data: comboQuarterData
			}),
			name: 'quarter',
			fieldLabel: '季',
			emptyText: '请选择',
			mode: 'local',
			triggerAction: 'all',
			valueField: 'value',
			displayField: 'text',
			itemCls: 'form_text',
			id: 'quarterOne',
			editable: false,
			columnWidth: .3
		});
		
		var monthOne = new Ext.form.ComboBox({
			store: new Ext.data.SimpleStore({
				fields: ['value', 'text'],
				data: comboMonthData
			}),
			name: 'month',
			fieldLabel: '月',
			emptyText: '请选择',
			mode: 'local',
			triggerAction: 'all',
			valueField: 'value',
			displayField: 'text',
			itemCls: 'form_text',
			id: 'monthOne',
			editable: false,
			columnWidth: .3
		});
		
		var tab_time = new Ext.Panel({
			title: '选择区间',
			layout: 'column',
			id: 'tab_timeZone',
			plain: true,
			frame: true,
			cls: "clear_l",
			hidden: 'true',
			items:[yearOne,quarterOne,monthOne]
		});
		
		var statisticsForm = new Ext.form.FormPanel({

			labelAlign: 'right',
			labelWidth: 80,
			frame: true,
			width: 400,
			items: [{
				xtype: 'combo',
				store: contributeCompanyList,
				hiddenName: 'contributeCompanyId',
				allowBlank: false,
				editable: false,
				fieldLabel: '投稿单位',
				emptyText: '请选择',
				mode: 'local',
				triggerAction: 'all',
				valueField: 'contributeCompanyId',
				displayField: 'contributeCompanyName',
				itemCls: 'form_text'
			}, {
				autoHeight: true,
				hideLabels: true,
				defaultType: 'radio',
				width: 200,
				items: [{
					boxLabel: '按年统计',
					name: 'periodType',
					inputValue: 1,
					id: 'workloadRadioOne',
					listeners: {
					'check': function(obj, checked){
					if (checked) {
						tab_time.show();
						yearOne.show();
						quarterOne.hide();
						monthOne.hide();
					}
				}
				}
				}, {
					boxLabel: '按季统计',
					name: 'periodType',
					inputValue: 2,
					id: 'workloadRadioTwo',
					listeners: {
					'check': function(obj, checked){
					if (checked) {
						tab_time.show();
						yearOne.show();
						quarterOne.show();
						monthOne.hide();
					}
				}
				}
				}, {
					boxLabel: '按月统计',
					name: 'periodType',
					inputValue: 3,
					id: 'workloadRadioThree',
					listeners: {
						'check': function(obj, checked){
							if (checked) {
								tab_time.show();
								yearOne.show();
								quarterOne.hide();
								monthOne.show();
							}
					}
				}

				}]
			}, tab_time],
			buttons: [{
				text: '统计',
				type: 'submit',
				handler: function(){
				
				var flag = true;
				if (!Ext.getCmp('workloadRadioOne').checked &&
						!Ext.getCmp('workloadRadioTwo').checked &&
						!Ext.getCmp('workloadRadioThree').checked) {
					flag = false;
				}
				else {
					if (Ext.getCmp('workloadRadioOne').checked) {
						if (Ext.getCmp('yearOne').getValue() ==
						'') {
							flag = false;
						}
					}
					else 
						if (Ext.getCmp('workloadRadioTwo').checked) {
							if (Ext.getCmp('yearOne').getValue() ==
								'' ||
								Ext.getCmp('quarterOne').getValue() ==
							'') {
								flag = false;
							}
						}
				}
				if(flag == false)
				{
					Ext.Msg.show({
							title : '错误提示',
							msg : '请选择时间区间类型和对应的区间！',
							buttons : Ext.Msg.OK,
							icon : Ext.Msg.INFO,
							width : 200
						});
					return;
				}
				if (statisticsForm.form.isValid()) {
					statisticsForm.form.doAction('submit', {
								url : 'statistics_statisticsCompany_list.action',// 文件路径
								method : 'post',// 提交方法post或get
								params : {statType : statType,subjectType : 2},
								success : function(form, action) {
									
									companyName = action.result.contributecompanyName;
									Ext.getCmp('perC').setValue(companyName);
									
									ds.baseParams = statisticsForm.getForm().getValues();
									ds.load({
										params : {
											statType : statType,
											subjectType : 2
										}
									});
									
									window_statictics_manuscriptNum.close();
									
								},
								failure : function(form, action) {
									if (action.failureType == 'server') {
										Ext.Msg.show({
											title : '消息',
											msg : '操作失败',
											buttons : Ext.Msg.OK,
											icon : Ext.Msg.INFO,
											width : 200
										});
									} else 
	                                    if (action.failureType == 'connect') {
	                                        Ext.Msg.show({
												title : '连接错误',
												msg : '指定路径连接错误!',
												buttons : Ext.Msg.OK,
												icon : Ext.Msg.ERROR,
												width : 200
											});
	                                    }
	                                    else 
	                                        if (action.failureType == 'client') {
	                                            Ext.Msg.show({
													title : '提示',
													msg : '数据错误，非法提交',
													buttons : Ext.Msg.OK,
													icon : Ext.Msg.ERROR,
													width : 200
												});
	                                        }
	                                        else {
	                                            Ext.Msg.show({
													title : '警告',
													msg : '服务器数据传输错误',
													buttons : Ext.Msg.OK,
													icon : Ext.Msg.ERROR,
													width : 200
												});
	                                        }
								}
							});
				}
			}
		},{
			text:'取消',
			handler:function(){
			window_statictics_manuscriptNum.close();
		}
		}]
	});


		var window_statictics_manuscriptNum = new Ext.Window({
					title : value.text+'统计',
					width : 400,
					iconCls:value.iconCls,
					resizable : false,
					autoHeight : true,
					modal : true,
					closeAction : 'hide',
					closable : false,
					items : statisticsForm
				}).show();
	}
});
}



var picture = new Ext.Button({
	text : '生成柱状图',
	width : 100,
	iconCls:"statistics_bar",
	handler : function() {
		
		
		var chartPanel = new Ext.Panel({
			width : 536,
			height : 300,
			layout : 'fit',
			frame : true,
			items : {
				xtype : 'columnchart',
				url : 'images/charts.swf',
				store : ds,
				xField : 'statType',
				yField : 'num',
				listeners : {
					itemclick : function (o){
						var rec = ds.getAt(o.index);
						Ext.example.msg('Item Selected','You chose {0}.',rec.get('name') );
					}
				}
			}
		});
		
		var win_delete_work =new Ext.Window({
						title : '统计图',
						height:330,
						width: 550,
						closeAction : 'hide',
						closable : true,
						modal : true,
						items : [chartPanel]
					}).show();
		
	}
});

var comName2 = new Ext.form.Label({
	text: '投稿单位名称:',
	cls:'input_label_text'
});

var comName = new Ext.form.TextField({
    cls:'input_label',
    readOnly: true,
    id: 'perC'
});

var grid = new Ext.grid.GridPanel({
	title : '当前位置：投稿单位统计',
	loadMask : {
		msg : '数据加载中...'
	},
	ds : ds,
	store : ds,
	region : 'center',
	autoScroll : true,
	cm : cm,
//	autoExpandColumn : 1,
	tbar : [tbarName,picture,comName2,comName]
});

var p_statisticsCompany = {
	id : 'statisticsCompany-search',
	border : false,
	layout : 'border',
	items : [grid]
};
Ext.getCmp('content-panel').add(p_statisticsCompany);
Ext.getCmp('content-panel').layout.setActiveItem('statisticsCompany-search');
Ext.getCmp('content-panel').uxmodules="undefined";